;-*- coding: utf-8 -*-
; Fritz Kunze's emacs init file.
; 2008-08
; 
; 

;----
; loading custom commands and functions

(message "hey fritz - we are now processing our .emacs.el file")
(message "hey fritz - we are loading the file c:\\bin\\mksmin\\.emacs.el")

(message "hey fritz - we are loading the django-documentation emacs keyboard shortcuts")

(load-file (w32-short-file-name 
   "c:/bin/mksmin/start-emacs/django_emacs_kbd_shortcuts.el"))

(message "hey fritz - we've finished setting up some django documentation shortcuts")

(add-to-list 'load-path "~/.emacs.d")

(autoload 'rst-mode "rst" nil t)

;; The recommended way to associate files is to associate
;; them with emacsclientw.exe.  In order for this to work
;; when Emacs is not yet started, you will also need to
;; set the environment variable ALTERNATE_EDITOR to
;; runemacs.exe.  To open files in a running instance of
;; Emacs, you will need to add the following to your init
;; file: (server-start)

(server-start)

(message "hey fritz - we've set up runemacs and emacsclientw.exe")

;;
(message "hey fritz - we are now adding the org mode stuff")
;;
;; Begin by first adding in the latest versions of remember.el
;;
;;
;(setq load-path (cons (w32-short-file-name "C:/bin/mksmin/Remember/remember-2.0") load-path))
(add-to-list 'load-path "~/.emacs.d/remember-2.0")
;; 4.8.1 Setting up remember
;; -------------------------

;; The following customization will tell remember to use org files as
;; target, and to create annotations compatible with Org-mode links.

(setq org-directory "c:/bin/mksmin/Org/")
(setq org-default-notes-file "c:/bin/mksmin/Org/.notes")
;(setq remember-annotation-functions '(org-remember-annotation))
;     (setq remember-handler-functions '(org-remember-handler))
;     (add-hook 'remember-mode-hook 'org-remember-apply-template)

(require 'remember)
;;
;; If you are missing the function org-remember-insinuate try these forms
;;
;; (setq remember-annotation-functions '(org-remember-annotation))
;;     (setq remember-handler-functions '(org-remember-handler))
;;     (add-hook 'remember-mode-hook 'org-remember-apply-template)


;;
;; Setting up for PlannerMode

;; Add this to your .emacs:

;;   (require 'remember-planner)
;;   (setq remember-handler-functions '(remember-planner-append))
;;   (setq remember-annotation-functions planner-annotation-functions)
;;
;; Now the stuff for org follows...
;;


;; Org-mode settings
;; you can simply run Org directly from the distribution
;; directory by adding the lisp subdirectory to the Emacs
;; load path.  To do this, add the following line to
;; .emacs:

;;    (setq load-path (cons "~/path/to/orgdir/lisp" load-path))

;; If you plan to use code from the contrib subdirectory,
;; do a similar step for this directory:

;;     (setq load-path (cons "~/path/to/orgdir/contrib/lisp" load-path))

;(setq load-path (cons (w32-short-file-name "C:/bin/mksmin/odistr/org-6.05b/lisp") load-path))
;(setq load-path (cons (w32-short-file-name "C:/bin/mksmin/odistrs/org-6.05b/contrib/lisp") load-path))
(add-to-list 'load-path "~/.emacs.d/org-6.05b/lisp")
(add-to-list 'load-path "~/.emacs.d/org-6.05b/contrib/lisp")


;; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
;;
;; Furthermore, you must activate font-lock-mode in Org buffers, because significant functionality depends on font-locking being active.
;; You can do this with either one of the following two lines 
;;   (global-font-lock-mode 1)                     ; for all buffers
;;   (add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
;;
;; (add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only

(global-font-lock-mode 1)                     ; for all buffers

;;
;; If you are using CuaMode, you might want to disable the Org Mode keybindings for Shift+arrow keys by adding this line:
;; (setq org-CUA-compatible t)
;; With this change, the following replacements:
;;
;;
;;
;;  * S-RET --> C-S-RET
;;  * S-up --> M-p
;;  * S-down --> M-n
;;  * S-left --> M--
;;  * S-right --> M-+

(setq org-CUA-compatible t)

(message "hey fritz - org mode loading is done - try out - M-x org-mde see: C:\NP1\Get Organized with Emacs Org-mode.htm")


;;The following file lists some of the customizations I've installed
;;file:///C:/Users/fkunze/Documents/DOCLIB/xahlee%20emacs%20tutorial/xah_emacs_tutorial/emacs/xah_emacs_init.html


;; Set up recentf so I can get a list of recent files when I start
(recentf-mode 1)


;; Set up a alt-q as a convenient way to format paragraphs
;;(setq default-major-mode 'text-mode)
;;(setq-default default-fill-column 50)   ; Set word wrap margin to 50
;;(add-hook 'text-mode-hook
 ;;           '(lambda () (auto-fill-mode 1)))

;;(message "hey fritz - recent file list and paragraph formatter got loaded")

;; from: http://xahlee.org/emacs/emacs_display_faq.html
;; see: http://www.gnu.org/software/emacs/manual/html_node/emacs/Longlines.html
;;Question: How to have emacs display line numbers?
;;Answer: Alt+x line-number-mode. To always have it on, place the following in your emacs customization file

;;;(defun my-turn-on-line-number-mode () (line-number-mode 1))
;;;(add-hook 'text-mode-hook 'my-turn-on-line-number-mode)
;; I found the above modification seems to interfere with longlines-mode, so 
;; I am turning it off for the moment.
;;; I want to see if I can set up emacs so that I can enable this mode from the customization
;;; panel within emacs.  If I fail, I want to uncomment this next line.

;;(add-hook 'text-mode-hook (lambda () (flyspell-mode 1)))
(message "hey fritz - you just turned line numbers and spell mode on permanently")

;;Question: How to show the cursor's column position?

;;Answer Alt+x column-number-mode. To always have it on, put the following code in your ~/.emacs file: (column-number-mode t).
;;;
;;; I am going to try to use emacs customizations to change the way that I deal with 
;;; column-number-mode and line-number-mode.  Uncomment the following if this fails.
;;;

;;(column-number-mode t)
;;(line-number-mode 1)

(message "hey fritz - you just turned cursor column numbers on permanently")

;; from: http://xahlee.org/emacs/emacs_display_faq.html
;;question: How to set a margin on the right?
;;Use Alt+x longlines-mode, available in Emacs version 22. When this mode is on, lines will be wrapped at 72 chars length. To adjust the this margin, use Alt+x set-variable, and then set fill-column a desired value.  If you run the command longlines-show-hard-newlines or set the variable longlines-show-hard-newlines to t, hard newlines will be marked with a symbol. This makes errors easier to spot.  [you can still use alt-q to fill paragraphs] see:http://www.emacswiki.org/cgi-bin/emacs-en/LongLines

;;To always have longlines-mode mode on, put in your emacs customization file: (add-hook 'text-mode-hook (lambda () (longlines-mode t))).

;;Note: as of emacs 22 (released in mid 2007), longlines-mode is buggy, especially when you paste text.

(add-hook 'text-mode-hook (lambda () (longlines-mode t)))
;; now set emacs so text editing windows determine the column width
;; see: http://www.emacswiki.org/cgi-bin/wiki/EwoutStam
(setq longlines-wrap-follows-window-size t)
(setq window-min-width 1)

(message "hey fritz - I've now added long-lines-mode - you can still use alt-q but it's function is really different")
;;
;; add in xah lee's functions to remove hard returns.  I took these from one of files located here:
;; file:///C:/Users/fkunze/Documents/DOCLIB/xahlee%20emacs%20tutorial/xah_emacs_tutorial/emacs/xah_emacs_init.html
;;

(defun remove-hard-wrap-paragraph () 
  "Replace line endings into single spaces on the current paragraph."
  (interactive) 
  (let ((fill-column 90002000)) 
    (fill-paragraph nil)))

(defun remove-hard-wrap-region (start end)
  "Replace newline chars in region by single spaces." 
  (interactive "r")
  (let ((fill-column 90002000)) 
    (fill-region start end)))

(global-set-key (kbd "M-Q") 'remove-hard-wrap-paragraph)
(global-set-key (kbd "M-R") 'remove-hard-wrap-region)

(message "hey fritz - I've now added two functions, useful for working with text, from xah lee")



(defalias 'list-buffers 'ibuffer)
(message "hey fritz - you just replaced list-buffers with ibuffer")


;;(load (w32-short-file-name "c:/Program Files/acl81/eli/fi-site-init.el"))

;; to find a font
;;(w32-select-font)

;; sets % to the same function in vi
;; (global-set-key "%" 'match-paren)
;;    (defun match-paren (arg)
;;     "Go to the matching paren if on a paren; otherwise insert %."
;;       (interactive "p")
;;       (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
;;             ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
;;             (t (self-insert-command (or arg 1)))))

;; (message "hey fritz - % works the way it does in vi")
;; explorer
    ;; ----------
    ;;; Windows explorer to open current file - Arun Ravindran
    
    (defun explorer ()
      "Launch the windows explorer in the current directory and selects current file"
      (interactive)
      (w32-shell-execute
       "open"
       "explorer"
       (concat "/e,/select," (convert-standard-filename buffer-file-name))))
    
    (global-set-key [f12]         'explorer)        ; F12 - Open Explorer for the current file path

(message "hey fritz - you can now use f-12 to open explorer in the directory containing the file you opened")

;;; this must be loaded after the (load ... eli/fi-site-init.el) 
;;; to solve a compatibilty problem

(setq fi:eli-compatibility-mode nil)

(defun alisp ()
  (interactive)
  (let ((lisp-directory "C:\\Program Files\\acl81\\")
        (lisp-name "mlisp"))
    (fi:common-lisp (format "*%s*" lisp-name)
                    lisp-directory
                    (format "%s\\%s.exe" lisp-directory lisp-name)
                    (list "+B" "+cx" "+M")
                    fi:common-lisp-host
                    (format "%s.dxl" lisp-name))))



(defun add-to-load-path (path-string)
  (message (format "Passed %S..." path-string))
  (if (stringp path-string)
      (when (file-exists-p path-string)
	(message (format "Adding %S to load-path..." path-string))
	(add-to-list 'load-path (expand-file-name path-string)))
    (crs-add-to-load-path (car path-string))
    (if (cdr path-string)
	(crs-add-to-load-path (cdr path-string)))))


(message "Initialization complete") (sit-for 1)
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(column-number-mode t)
 '(cua-mode nil nil (cua-base))
 '(default-frame-alist (quote ((font . "-outline-Courier New-normal-r-normal-normal-21-157-96-96-c-*-iso8859-1") (top . 10) (left . 150) (tool-bar-lines . 1) (menu-bar-lines . 1) (right-fringe) (left-fringe))))
 '(grep-command "C:\\Windows\\System32\\findstr.exe -n -r  ")
 '(grep-use-null-device t)
 '(gud-pdb-command-name "python -m pdb")
 '(icicle-reminder-prompt-flag 0)
 '(ido-mode (quote both) nil (ido))
 '(inhibit-startup-screen t)
 '(ispell-program-name "C:\\Program Files\\Aspell\\bin\\aspell.exe")
 '(org-agenda-files (quote ("~/Org/personal.org")))
 '(python-python-command "C:/Python25/python.exe")
 '(recentf-max-saved-items 40)
 '(safe-local-variable-values (quote ((Package . NEWSCADE))))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-flyspell (lambda nil (longlines-mode t)) text-mode-hook-identify)))
 '(transient-mark-mode t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )



(put 'upcase-region 'disabled nil)

(put 'downcase-region 'disabled nil)
